using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Web.UI;

namespace ARF.Web.Utility
{
    public class Utility
    {
        public static void CleanXml(XmlDocument xml)
        {
            XmlTextReader oReader = new XmlTextReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ARF.Resources.CleanXml.xsl"));
            XslCompiledTransform oTransform = new XslCompiledTransform();
            oTransform.Load(oReader);

            System.IO.StringWriter sw = new System.IO.StringWriter();

            XmlTextWriter writer = new XmlTextWriter(sw);
            oTransform.Transform(xml, null, writer);
            xml.LoadXml(sw.ToString());
        }

        public static XmlDocument CleanXml(string xml)
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.LoadXml(xml);
            CleanXml(oDoc);
            return oDoc;
        }

        public static Control FindControlOnPage(Control callingControl, string QueryFilter)
        {
            Control c = callingControl.NamingContainer.FindControl(QueryFilter);
            if (c != null) return c;

            c = callingControl.Page.Form.FindControl(QueryFilter);
            if (c != null) return c;

            return null;
        }

    }
}
